//
//  TelevisionControl.m
//  iPhoneControlApplication
//
//  Created by Elliot Chapple on 11/04/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "TelevisionControl.h"


@implementation TelevisionControl

//Synth Objects
@synthesize		channelPlus;
@synthesize		channelMinus;
@synthesize		volumePlus;
@synthesize		volumeMinus;
@synthesize		button0;
@synthesize		button1;
@synthesize		button2;
@synthesize		button3;
@synthesize		button4;
@synthesize		button5;
@synthesize		button6;
@synthesize		button7;
@synthesize		button8;
@synthesize		button9;
@synthesize		selectButton;
@synthesize		leftArrow;
@synthesize		upArrow;
@synthesize		rightArrow;
@synthesize		downArrow;
@synthesize		channelLabel;

//Methods

-(IBAction)channelUpButtonPress
{
	NSString *currentValue = channelLabel.text;
	int newValue = [currentValue intValue];
	newValue = newValue + 1;
	NSString *updatedvalue = [[NSString alloc] initWithFormat:@"%d", newValue];
	channelLabel.text = updatedvalue;
	//NSString *channelTitle = channelLabel.text;
	NSString *newText = [[NSString alloc] initWithFormat:@"Now Viewing Channel:  %@.", updatedvalue];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TV Programme Changed" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
}



-(IBAction)channelDownButtonPress
{
	//Code basis courtesy of Apple Inc
	
	NSString *currentValue = channelLabel.text;
	int newValue = [currentValue intValue];
	newValue = newValue - 1;
	NSString *updatedvalue = [[NSString alloc] initWithFormat:@"%d", newValue];
	channelLabel.text = updatedvalue;
	//NSString *channelTitle = channelLabel.text;
	NSString *newText = [[NSString alloc] initWithFormat:@"Now Viewing Channel:  %@.", updatedvalue];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TV Programme Changed" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
}


-(IBAction)volumeUpButtonPress
{
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Volume Increased" message:nil delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
}


-(IBAction)volumeDownButtonPress
{
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Volume Decreased" message:nil delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
}


-(IBAction)numberButtonPress:(id)sender
{
	NSString *title = [sender titleForState:UIControlStateNormal];
	NSString *newText = [[NSString alloc] initWithFormat:@"The %@ has been selected", title];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Selected" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
}


-(IBAction)navigationButtonPress:(id)sender
{
	NSString *title = [sender titleForState:UIControlStateNormal];
	NSString *newText = [[NSString alloc] initWithFormat:@"The %@ has been selected", title];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Selected" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
[newText release];}


-(IBAction)selectButtonPress
{
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Item Selected" message:nil delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
}













//Apple Code as in previous
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	//Add user notification to show which area is being controlled
	NSString *newText = [[NSString alloc] initWithFormat:@"This application is now simulating control of a Television Device"];
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Established" message:newText delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
	[alert show];
	[alert release];
	[newText release];
	
	//For the select button
	
	UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
	UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[/*Put button name here*/ selectButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
	UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[/*Put button name here*/ selectButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
	
	
	/*
	//Overriding the defaults for the rect buttons for the channel number buttons
	//For t button
	UIImage *buttonImageNormal = [UIImage imageNamed:@"MC Zero Button (70x70).png"];
	UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button0 setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed = [UIImage imageNamed:@"MC 0 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[button0 setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
	
	
	//For the 1 button
	UIImage *buttonImageNormal1 = [UIImage imageNamed:@"MC One Button (40x40).png"];
	UIImage *stretchableButtonImageNormal1 = [buttonImageNormal1 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[button1 setBackgroundImage:stretchableButtonImageNormal1 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed1 = [UIImage imageNamed:@"MC 1 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed1 = [buttonImagePressed1 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[button1 setBackgroundImage:stretchableButtonImagePressed1 forState:UIControlStateHighlighted];
	
	
	//For the 2 button
	UIImage *buttonImageNormal2 = [UIImage imageNamed:@"MC Two Button (70x70).png"];
	UIImage *stretchableButtonImageNormal2 = [buttonImageNormal2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button2 setBackgroundImage:stretchableButtonImageNormal2 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed2 = [UIImage imageNamed:@"MC 2 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed2 = [buttonImagePressed2 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button2 setBackgroundImage:stretchableButtonImagePressed2 forState:UIControlStateHighlighted];
	
	
	//For the 3 button
	UIImage *buttonImageNormal3 = [UIImage imageNamed:@"MC Three Button (70x70).png"];
	UIImage *stretchableButtonImageNormal3 = [buttonImageNormal3 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[
	 button3 setBackgroundImage:stretchableButtonImageNormal3 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed3 = [UIImage imageNamed:@"MC 3 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed3 = [buttonImagePressed3 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button3 setBackgroundImage:stretchableButtonImagePressed3 forState:UIControlStateHighlighted];
	
	
	//For the 4 button
	UIImage *buttonImageNormal4 = [UIImage imageNamed:@"MC Four Button (70x70).png"];
	UIImage *stretchableButtonImageNormal4 = [buttonImageNormal4 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button4 setBackgroundImage:stretchableButtonImageNormal4 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed4 = [UIImage imageNamed:@"MC 4 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed4 = [buttonImagePressed4 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button4 setBackgroundImage:stretchableButtonImagePressed4 forState:UIControlStateHighlighted];
	
	
	//For the 5 button
	UIImage *buttonImageNormal5 = [UIImage imageNamed:@"MC Five Button (70x70).png"];
	UIImage *stretchableButtonImageNormal5 = [buttonImageNormal5 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button5 setBackgroundImage:stretchableButtonImageNormal5 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed5 = [UIImage imageNamed:@"MC 5 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed5 = [buttonImagePressed5 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button5 setBackgroundImage:stretchableButtonImagePressed5 forState:UIControlStateHighlighted];
	
	
	//For the 6 button
	UIImage *buttonImageNormal6 = [UIImage imageNamed:@"MC Six Button (70x70).png"];
	UIImage *stretchableButtonImageNormal6 = [buttonImageNormal6 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button6 setBackgroundImage:stretchableButtonImageNormal6 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed6 = [UIImage imageNamed:@"MC 6 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed6 = [buttonImagePressed6 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button6 setBackgroundImage:stretchableButtonImagePressed6 forState:UIControlStateHighlighted];
	
	
	//For the 7 button
	UIImage *buttonImageNormal7 = [UIImage imageNamed:@"MC Seven Button (70x70).png"];
	UIImage *stretchableButtonImageNormal7 = [buttonImageNormal7 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button7 setBackgroundImage:stretchableButtonImageNormal7 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed7 = [UIImage imageNamed:@"MC 7 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed7 = [buttonImagePressed7 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button7 setBackgroundImage:stretchableButtonImagePressed7 forState:UIControlStateHighlighted];
	
	
	//For the 8 button
	UIImage *buttonImageNormal8 = [UIImage imageNamed:@"MC Eight Button (70x70).png"];
	UIImage *stretchableButtonImageNormal8 = [buttonImageNormal8 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button8 setBackgroundImage:stretchableButtonImageNormal8 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed8 = [UIImage imageNamed:@"MC 8 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed8 = [buttonImagePressed8 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button8 setBackgroundImage:stretchableButtonImagePressed8 forState:UIControlStateHighlighted];
	
	
	//For the 9 button
	UIImage *buttonImageNormal9 = [UIImage imageNamed:@"MC Nine Button (70x70).png"];
	UIImage *stretchableButtonImageNormal9 = [buttonImageNormal9 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button9 setBackgroundImage:stretchableButtonImageNormal9 forState:UIControlStateNormal];
	
	UIImage *buttonImagePressed9 = [UIImage imageNamed:@"MC 9 Button Selected (70x70).png"];
	UIImage *stretchableButtonImagePressed9 = [buttonImagePressed9 stretchableImageWithLeftCapWidth:12 topCapHeight:0];
	[ button9 setBackgroundImage:stretchableButtonImagePressed9 forState:UIControlStateHighlighted];
	*/
	
	
	
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}


@end
